﻿using System.Windows.Controls;
using System.ComponentModel;
using System.Windows.Media.Imaging;
using System.Windows;

namespace CharacterCreation.Views.Contracts {
    /// <summary>
    /// A base view
    /// </summary>
    public class BaseView : UserControl, INotifyPropertyChanged {

        /// <summary>
        /// Gets or sets the HeaderText
        /// </summary>
        public string HeaderText {
            get { return _HeaderText; }
            set {
                _HeaderText = value;
                RaisePropertyChanged("HeaderText");
            }
        }
        private string _HeaderText;

        /// <summary>
        /// This property should be supplied when adding a view to the main page's view collection
        /// </summary>
        public BitmapSource ViewImage {
            get {
                if (_ViewImage == null)
                    _ViewImage = new BitmapImage(new System.Uri("/CharacterCreation;component/Images/home_32.png", System.UriKind.RelativeOrAbsolute));
                return _ViewImage;
            }
            set { _ViewImage = value; }
        }
        private BitmapSource _ViewImage;

        /// <summary>
        /// Gets or sets the ViewModel
        /// </summary>
        public BaseViewModel ViewModel {
            get { return _ViewModel; }
            set {
                _ViewModel = value;

                this.DataContext = _ViewModel;
                this.IsPopup = false;

                value.BaseView = this;
                value.IsNewItem = false;

                RaisePropertyChanged("ViewModel");
            }
        }
        private BaseViewModel _ViewModel;

        /// <summary>
        /// Gets or sets the IsNewItem
        /// </summary>
        public bool IsNewItem {
            get { return this.ViewModel.IsNewItem; }
            set { this.ViewModel.IsNewItem = value; }
        }

        /// <summary>
        /// Gets or sets the IsPopup
        /// </summary>
        public bool IsPopup {
            get { return this.ViewModel.IsPopup; }
            set { this.ViewModel.IsPopup = value; }
        }
        public static readonly DependencyProperty IsPopupProperty =
            DependencyProperty.Register("IsPopup", typeof(bool), typeof(BaseView), null);

        /// <summary>
        /// Raises the property changed event
        /// </summary>
        /// <param name="propertyName"></param>
        public void RaisePropertyChanged(string propertyName) {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        /// <summary>
        /// The property changed event
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

    }
}
